﻿Imports System.Windows.Forms
Imports System.Collections.Specialized
Imports System.Text.RegularExpressions
Public Class ListInOut

#Region ""
    Private WithEvents _InOutForm As New InOutForm

    Private Sub LoadData()
        Dim 开始时间 As Date = New Date(Me.dtFindDate.Value.Year, Me.dtFindDate.Value.Month, 1)
        Dim 结束时间 As Date = New Date(Me.dtFindDate1.Value.Year, Me.dtFindDate1.Value.Month, 1)
        If 开始时间 > 结束时间 Then
            Exit Sub
        End If
        Dim dt As New DataTable
        Dim dc As DataColumn
        dt.Columns.Add("用户月")
        dt.Columns.Add("月份")
        dc = dt.Columns.Add("收入", GetType(Decimal))
        dc.DefaultValue = 0
        dt.Columns.Add("支出", GetType(Decimal))
        dt.Columns.Add("统计", GetType(Decimal))
        dc = dt.Columns.Add("用户ID月")
        dc.DefaultValue = ""
        '抽数据
        Dim Year As Integer = Me.dtFindDate.Value.Year
        Dim strSql As String = String.Empty
        Dim strSql1 As String = String.Empty
        Dim dr As DataRow

        Dim dt用户 As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by UserIndex")

        If chk用户月.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                For Year = 开始时间.Year To 结束时间.Year
                    Dim 开始月 As Integer = 1
                    Dim 结束月 As Integer = 12
                    If Year = 开始时间.Year Then
                        开始月 = 开始时间.Month
                    End If
                    If Year = 结束时间.Year Then
                        结束月 = 结束时间.Month
                    End If

                    For endmouth As Integer = 开始月 To 结束月
                        Dim day As Integer = DateTime.DaysInMonth(Year, endmouth)
                        Dim strBegin As String = Year.ToString("0000") + "-" + endmouth.ToString("00") + "-" + 1.ToString("00")
                        Dim strEnd As String = Year.ToString("0000") + "-" + endmouth.ToString("00") + "-" + day.ToString("00")

                        strSql = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "' AND username='" + CStr(dr用户("id")) + "'"
                        strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "' AND username='" + CStr(dr用户("id")) + "'"

                        dr = dt.NewRow
                        dr(0) = dr用户("username")

                        If endmouth = 1 Then
                            dr(1) = "01月"
                        ElseIf endmouth = 2 Then
                            dr(1) = "02月"
                        ElseIf endmouth = 3 Then
                            dr(1) = "03月"
                        ElseIf endmouth = 4 Then
                            dr(1) = "04月"
                        ElseIf endmouth = 5 Then
                            dr(1) = "05月"
                        ElseIf endmouth = 6 Then
                            dr(1) = "06月"
                        ElseIf endmouth = 7 Then
                            dr(1) = "07月"
                        ElseIf endmouth = 8 Then
                            dr(1) = "08月"
                        ElseIf endmouth = 9 Then
                            dr(1) = "09月"
                        ElseIf endmouth = 10 Then
                            dr(1) = "10月"
                        ElseIf endmouth = 11 Then
                            dr(1) = "11月"
                        ElseIf endmouth = 12 Then
                            dr(1) = "12月"
                        End If

                        dr(1) = Year.ToString & "年" & CStr(dr(1))
                        Dim dt2 As DataTable = ct.FillTable(strSql)
                        If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                            dr(2) = 结果(dt2.Rows(0)(0))
                        Else
                            dr(2) = 0
                        End If
                        dt2 = ct.FillTable(strSql1)
                        If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                            dr(3) = 结果(dt2.Rows(0)(0))
                        Else
                            dr(3) = 0
                        End If
                        dr(4) = CDec(dr(2)) - CDec(dr(3))
                        dr(5) = dr用户("ID")
                        dt.Rows.Add(dr)
                    Next
                Next
            Next
        Else
            For Year = 开始时间.Year To 结束时间.Year
                Dim 开始月 As Integer = 1
                Dim 结束月 As Integer = 12
                If Year = 开始时间.Year Then
                    开始月 = 开始时间.Month
                End If
                If Year = 结束时间.Year Then
                    结束月 = 结束时间.Month
                End If
                For endmouth As Integer = 开始月 To 结束月
                    Dim day As Integer = DateTime.DaysInMonth(Year, endmouth)
                    Dim strBegin As String = Year.ToString("0000") + "-" + endmouth.ToString("00") + "-" + 1.ToString("00")
                    Dim strEnd As String = Year.ToString("0000") + "-" + endmouth.ToString("00") + "-" + day.ToString("00")
                    strSql = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "'"
                    strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "'"

                    dr = dt.NewRow

                    If endmouth = 1 Then
                        dr(1) = "01月"
                    ElseIf endmouth = 2 Then
                        dr(1) = "02月"
                    ElseIf endmouth = 3 Then
                        dr(1) = "03月"
                    ElseIf endmouth = 4 Then
                        dr(1) = "04月"
                    ElseIf endmouth = 5 Then
                        dr(1) = "05月"
                    ElseIf endmouth = 6 Then
                        dr(1) = "06月"
                    ElseIf endmouth = 7 Then
                        dr(1) = "07月"
                    ElseIf endmouth = 8 Then
                        dr(1) = "08月"
                    ElseIf endmouth = 9 Then
                        dr(1) = "09月"
                    ElseIf endmouth = 10 Then
                        dr(1) = "10月"
                    ElseIf endmouth = 11 Then
                        dr(1) = "11月"
                    ElseIf endmouth = 12 Then
                        dr(1) = "12月"
                    End If
                    dr(1) = Year.ToString & "年" & CStr(dr(1))
                    Dim dt2 As DataTable = ct.FillTable(strSql)
                    If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                        dr(2) = 结果(dt2.Rows(0)(0))
                    Else
                        dr(2) = 0
                    End If
                    dt2 = ct.FillTable(strSql1)
                    If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                        dr(3) = 结果(dt2.Rows(0)(0))
                    Else
                        dr(3) = 0
                    End If
                    dr(4) = CDec(dr(2)) - CDec(dr(3))
                    dt.Rows.Add(dr)
                Next
            Next
        End If

        Dim dr合计 As DataRow = dt.NewRow
        dr合计(1) = ""
        dr合计(2) = 0
        dr合计(3) = 0
        dr合计(4) = 0

        dr合计(1) = "总合计"
        For i As Integer = 0 To dt.Rows.Count - 1
            dr合计(2) += 结果(dt.Rows(i)(2))
            dr合计(3) += 结果(dt.Rows(i)(3))
            dr合计(4) += 结果(dt.Rows(i)(4))
        Next

        If chk用户月.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                dr = dt.NewRow
                dr(0) = dr用户("username")
                dr(2) = 0
                dr(3) = 0
                dr(4) = 0
                dr(5) = dr用户("id")
                dr(1) = "小计"
                For i As Integer = 0 To dt.Rows.Count - 1
                    If CStr(dt.Rows(i)("用户ID月")).Trim = CStr(dr用户("id")).Trim Then
                        dr(2) += 结果(dt.Rows(i)(2))
                        dr(3) += 结果(dt.Rows(i)(3))
                        dr(4) += 结果(dt.Rows(i)(4))
                    End If
                Next
                dt.Rows.Add(dr)
            Next
        End If
        '合计行
        dt.Rows.Add(dr合计)

        Me.DataGridView1.DataSource = dt
        If chk用户月.Checked Then
            Me.DataGridView1.Columns("用户月").Visible = True
            Me.DataGridView1.Width = 637
        Else
            Me.DataGridView1.Columns("用户月").Visible = False
            Me.DataGridView1.Width = 537
        End If
        Me.DataGridView1.Columns("用户ID月").Visible = False
        着色(DataGridView1)
    End Sub
#End Region

    Private Sub LoadData1()
        Dim 开始时间 As Date = New Date(Me.dt开始日.Value.Year, Me.dt开始日.Value.Month, dt开始日.Value.Day)
        Dim 结束时间 As Date = New Date(Me.dt结束日.Value.Year, Me.dt结束日.Value.Month, dt结束日.Value.Day)
        If 开始时间 > 结束时间 Then
            Exit Sub
        End If

        Dim dt As New DataTable
        Dim dc As DataColumn
        dt.Columns.Add("用户日")
        dt.Columns.Add("月份")
        dc = dt.Columns.Add("收入", GetType(Decimal))
        dc.DefaultValue = 0
        dt.Columns.Add("支出", GetType(Decimal))
        dt.Columns.Add("统计", GetType(Decimal))
        dc = dt.Columns.Add("用户ID日")
        dc.DefaultValue = ""
        '抽数据
        Dim Year As Integer = Me.dtFindDate.Value.Year
        Dim endmouth As Integer = 0
        Dim strSql As String = String.Empty
        Dim strSql1 As String = String.Empty
        Dim dr As DataRow

        Dim dt用户 As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by UserIndex")
        If chk用户日.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                For Year = dt开始日.Value.Year To dt结束日.Value.Year
                    Dim 开始月 As Integer = 1
                    Dim 结束月 As Integer = 12
                    If Year = dt开始日.Value.Year Then
                        开始月 = dt开始日.Value.Month
                    End If
                    If Year = dt结束日.Value.Year Then
                        结束月 = dt结束日.Value.Month
                    End If
                    For endmouth = 开始月 To 结束月
                        Dim 开始日 As Integer = 1
                        Dim 结束日 As Integer = DateTime.DaysInMonth(Year, endmouth)
                        If Year = dt开始日.Value.Year AndAlso endmouth = dt开始日.Value.Month Then
                            开始日 = dt开始日.Value.Day
                        End If
                        If Year = dt结束日.Value.Year AndAlso endmouth = dt结束日.Value.Month Then
                            结束日 = dt结束日.Value.Day
                        End If
                        For day As Integer = 开始日 To 结束日
                            Dim strBegin As String = Year.ToString("0000") + "-" + endmouth.ToString("00") + "-" + day.ToString("00")
                            strSql = "select  sum(count) as count from WysInput where date([DateTime])='" + strBegin + "' AND username='" + CStr(dr用户("id")) + "'"
                            strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])='" + strBegin + "' AND username='" + CStr(dr用户("id")) + "'"

                            dr = dt.NewRow
                            dr(0) = dr用户("username")
                            dr(1) = Year.ToString("0000") & "年" & endmouth.ToString("00") & "月" & day.ToString("00") & "日"
                            Dim dt2 As DataTable = ct.FillTable(strSql)
                            If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                                dr(2) = 结果(dt2.Rows(0)(0))
                            Else
                                dr(2) = 0
                            End If
                            dt2 = ct.FillTable(strSql1)
                            If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                                dr(3) = 结果(dt2.Rows(0)(0))
                            Else
                                dr(3) = 0
                            End If
                            dr(4) = CDec(dr(2)) - CDec(dr(3))
                            dr(5) = dr用户("ID")
                            dt.Rows.Add(dr)
                        Next
                    Next
                Next
            Next
        Else
            For Year = dt开始日.Value.Year To dt结束日.Value.Year
                Dim 开始月 As Integer = 1
                Dim 结束月 As Integer = 12
                If Year = dt开始日.Value.Year Then
                    开始月 = dt开始日.Value.Month
                End If
                If Year = dt结束日.Value.Year Then
                    结束月 = dt结束日.Value.Month
                End If
                For endmouth = 开始月 To 结束月
                    Dim 开始日 As Integer = 1
                    Dim 结束日 As Integer = DateTime.DaysInMonth(Year, endmouth)
                    If Year = dt开始日.Value.Year AndAlso endmouth = dt开始日.Value.Month Then
                        开始日 = dt开始日.Value.Day
                    End If
                    If Year = dt结束日.Value.Year AndAlso endmouth = dt结束日.Value.Month Then
                        结束日 = dt结束日.Value.Day
                    End If
                    For day As Integer = 开始日 To 结束日
                        Dim strBegin As String = Year.ToString("0000") + "-" + endmouth.ToString("00") + "-" + day.ToString("00")
                        strSql = "select  sum(count) as count from WysInput where date([DateTime])='" + strBegin + "'"
                        strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])='" + strBegin + "'"

                        dr = dt.NewRow
                        dr(1) = Year.ToString("0000") & "年" & endmouth.ToString("00") & "月" & day.ToString("00") & "日"
                        Dim dt2 As DataTable = ct.FillTable(strSql)
                        If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                            dr(2) = 结果(dt2.Rows(0)(0))
                        Else
                            dr(2) = 0
                        End If
                        dt2 = ct.FillTable(strSql1)
                        If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                            dr(3) = 结果(dt2.Rows(0)(0))
                        Else
                            dr(3) = 0
                        End If
                        dr(4) = CDec(dr(2)) - CDec(dr(3))

                        dt.Rows.Add(dr)
                    Next
                Next
            Next
        End If

        'dr = dt.NewRow
        'dr(2) = 0
        'dr(3) = 0
        'dr(4) = 0

        'dr(1) = "合计"
        'For i As Integer = 0 To dt.Rows.Count - 1
        '    dr(2) += 结果(dt.Rows(i)(2))
        '    dr(3) += 结果(dt.Rows(i)(3))
        '    dr(4) += 结果(dt.Rows(i)(4))
        'Next
        'dt.Rows.Add(dr)

        Dim dr合计 As DataRow = dt.NewRow
        dr合计(1) = ""
        dr合计(2) = 0
        dr合计(3) = 0
        dr合计(4) = 0

        dr合计(1) = "总合计"
        For i As Integer = 0 To dt.Rows.Count - 1
            dr合计(2) += 结果(dt.Rows(i)(2))
            dr合计(3) += 结果(dt.Rows(i)(3))
            dr合计(4) += 结果(dt.Rows(i)(4))
        Next

        If chk用户日.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                dr = dt.NewRow
                dr(0) = dr用户("username")
                dr(2) = 0
                dr(3) = 0
                dr(4) = 0
                dr(5) = dr用户("id")

                dr(1) = "小计"
                For i As Integer = 0 To dt.Rows.Count - 1
                    If CStr(dt.Rows(i)("用户ID日")).Trim = CStr(dr用户("id")).Trim Then
                        dr(2) += 结果(dt.Rows(i)(2))
                        dr(3) += 结果(dt.Rows(i)(3))
                        dr(4) += 结果(dt.Rows(i)(4))
                    End If
                Next
                dt.Rows.Add(dr)
            Next
        End If
        '合计行
        dt.Rows.Add(dr合计)
        Me.DataGridView2.DataSource = dt
        If chk用户日.Checked Then
            Me.DataGridView2.Columns("用户日").Visible = True
            Me.DataGridView2.Width = 637
        Else
            Me.DataGridView2.Columns("用户日").Visible = False
            Me.DataGridView2.Width = 537
        End If
        Me.DataGridView2.Columns("用户ID日").Visible = False
        着色(DataGridView2)
    End Sub

    Private Sub LoadData2()

        Dim date1 As DateTime = New Date(dt开始年.Value.Year, 1, 1)
        Dim date2 As DateTime = New Date(dt结束年.Value.Year, 1, 1)

        Dim dt3 As DataTable = ct.FillTable("select  sum(count) as count from WysInput")
        If dt3.Rows.Count > 0 Then
            Me.txt总收入.Text = dt3.Rows(0)("count")
        End If
        dt3 = ct.FillTable("select  sum(count) as count from WysOutput ")
        If dt3.Rows.Count > 0 Then
            Me.txt总支出.Text = dt3.Rows(0)("count")
        End If

        If date1 > date2 Then
            Me.DataGridView3.DataSource = Nothing
            Exit Sub
        End If

        Dim dt As New DataTable
        Dim dc As DataColumn
        dt.Columns.Add("用户")
        dt.Columns.Add("月份")
        dc = dt.Columns.Add("收入", GetType(Decimal))
        dc.DefaultValue = 0

        dt.Columns.Add("支出", GetType(Decimal))
        dt.Columns.Add("统计", GetType(Decimal))
        dc = dt.Columns.Add("用户ID")
        dc.DefaultValue = ""
        '抽数据
        Dim Year1 As Integer = Me.dt开始年.Value.Year
        Dim Year2 As Integer = Me.dt结束年.Value.Year

        Dim strSql As String = String.Empty
        Dim strSql1 As String = String.Empty
        Dim dr As DataRow

        Dim dt用户 As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by UserIndex")
        If chk用户.Checked Then
            If dt用户.Rows.Count > 0 Then
                For Each dr用户 As DataRow In dt用户.Rows
                    For Year As Integer = Year1 To Year2

                        Dim strBegin As String = Year.ToString("0000") + "-" + 1.ToString("00") + "-" + 1.ToString("00")
                        Dim strEnd As String = Year.ToString("0000") + "-" + 12.ToString("00") + "-" + 31.ToString("00")
                        strSql = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "' AND username='" + CStr(dr用户("id")) + "'"
                        strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "' AND username='" + CStr(dr用户("id")) + "'"

                        dr = dt.NewRow
                        dr(0) = dr用户("username")
                        dr(1) = Year.ToString + "年"

                        Dim dt2 As DataTable = ct.FillTable(strSql)
                        If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                            dr(2) = 结果(dt2.Rows(0)(0))
                        Else
                            dr(2) = 0
                        End If
                        dt2 = ct.FillTable(strSql1)
                        If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                            dr(3) = 结果(dt2.Rows(0)(0))
                        Else
                            dr(3) = 0
                        End If
                        dr(4) = CDec(dr(2)) - CDec(dr(3))
                        dr(5) = dr用户("ID")
                        dt.Rows.Add(dr)
                    Next
                Next
            End If
        Else
            For Year As Integer = Year1 To Year2
                Dim strBegin As String = Year.ToString("0000") + "-" + 1.ToString("00") + "-" + 1.ToString("00")
                Dim strEnd As String = Year.ToString("0000") + "-" + 12.ToString("00") + "-" + 31.ToString("00")
                strSql = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "'"
                strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' AND date([DateTime])<='" + strEnd + "'"

                dr = dt.NewRow
                dr(0) = ""
                dr(1) = Year.ToString + "年"

                Dim dt2 As DataTable = ct.FillTable(strSql)
                If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                    dr(2) = 结果(dt2.Rows(0)(0))
                Else
                    dr(2) = 0
                End If
                dt2 = ct.FillTable(strSql1)
                If dt2 IsNot Nothing AndAlso dt2.Rows.Count > 0 Then
                    dr(3) = 结果(dt2.Rows(0)(0))
                Else
                    dr(3) = 0
                End If
                dr(4) = CDec(dr(2)) - CDec(dr(3))
                dt.Rows.Add(dr)
            Next
        End If

        Dim dr合计 As DataRow = dt.NewRow
        dr合计(1) = ""
        dr合计(2) = 0
        dr合计(3) = 0
        dr合计(4) = 0

        dr合计(1) = "总合计"
        For i As Integer = 0 To dt.Rows.Count - 1
            dr合计(2) += 结果(dt.Rows(i)(2))
            dr合计(3) += 结果(dt.Rows(i)(3))
            dr合计(4) += 结果(dt.Rows(i)(4))
        Next

        If chk用户.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                dr = dt.NewRow
                dr(0) = dr用户("username")
                dr(2) = 0
                dr(3) = 0
                dr(4) = 0
                dr(5) = dr用户("id")
                dr(1) = "小计"
                For i As Integer = 0 To dt.Rows.Count - 1
                    If CStr(dt.Rows(i)("用户ID")).Trim = CStr(dr用户("id")).Trim Then
                        dr(2) += 结果(dt.Rows(i)(2))
                        dr(3) += 结果(dt.Rows(i)(3))
                        dr(4) += 结果(dt.Rows(i)(4))
                    End If
                Next
                dt.Rows.Add(dr)
            Next
        End If

        '合计行
        dt.Rows.Add(dr合计)

        Me.DataGridView3.DataSource = dt
        If chk用户.Checked Then
            Me.DataGridView3.Columns("用户").Visible = True
            Me.DataGridView3.Width = 637
        Else
            Me.DataGridView3.Columns("用户").Visible = False
            Me.DataGridView3.Width = 537
        End If
        Me.DataGridView3.Columns("用户ID").Visible = False
        着色(DataGridView3)
    End Sub

    Private Sub LoadData3()
        Dim 开始时间 As Date = New Date(Me.dt开始分类.Value.Year, Me.dt开始分类.Value.Month, dt开始分类.Value.Day)
        Dim 结束时间 As Date = New Date(Me.dt结束分类.Value.Year, Me.dt结束分类.Value.Month, dt结束分类.Value.Day)
        If 开始时间 > 结束时间 Then
            Exit Sub
        End If

        Dim dt As New DataTable
        Dim dc As DataColumn
        dt.Columns.Add("支出用户")
        dt.Columns.Add("支出大类")
        dt.Columns.Add("支出小类")
        dc = dt.Columns.Add("合计", GetType(Decimal))
        dc.DefaultValue = 0
        dt.Columns.Add("分类ID")
        dc = dt.Columns.Add("支出用户ID")
        dc.DefaultValue = ""
        '抽数据
        Dim Year As Integer = Me.dtFindDate.Value.Year
        Dim endmouth As Integer = 0
        Dim strSql As String = String.Empty
        Dim strSql1 As String = String.Empty
        Dim dr As DataRow
        Dim strBegin As String = dt开始分类.Value.Year.ToString("0000") + "-" + dt开始分类.Value.Month.ToString("00") + "-" + dt开始分类.Value.Day.ToString("00")
        Dim strEnd As String = dt结束分类.Value.Year.ToString("0000") + "-" + dt结束分类.Value.Month.ToString("00") + "-" + dt结束分类.Value.Day.ToString("00")

        Dim dt用户 As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by UserIndex")
        If chk支出用户.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                Dim dt支出类型 As DataTable = ct.FillTable("select * from XscBugType where ParentID=179 ")
                For Each dr2 As DataRow In dt支出类型.Rows
                    Dim dt支出类型1 As DataTable = ct.FillTable("select * from XscBugType where ParentID= " & CStr(dr2("id")))
                    Dim drNew As DataRow = dt.NewRow
                    drNew(0) = dr用户("username")
                    drNew(1) = "+" & dr2("name")
                    drNew(2) = ""
                    drNew(3) = 0
                    drNew(4) = dr2("ID")
                    drNew(5) = dr用户("ID")
                    dt.Rows.Add(drNew)

                    strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr2("id") & " AND username='" + CStr(dr用户("id")) + "'")
                    Dim dtParnet As DataTable = ct.FillTable(strSql1)
                    If dtParnet.Rows.Count > 0 Then
                        drNew(3) = 金额(dtParnet.Rows(0)("count"))
                    End If

                    If dt支出类型1.Rows.Count > 0 Then
                        drNew(1) = "+" & dr2("name") & "(" & dt支出类型1.Rows.Count.ToString & "个小类" & ")"
                        For Each dr3 As DataRow In dt支出类型1.Rows
                            strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr3("id") & " AND username='" + CStr(dr用户("id")) + "'")
                            dtParnet = ct.FillTable(strSql1)
                            Dim drNew1 As DataRow = dt.NewRow
                            drNew1(1) = ""
                            drNew1(2) = dr3("name")
                            drNew1(3) = 0
                            drNew1(4) = dr3("ID")
                            drNew(4) = drNew(4) & "," & dr3("ID")
                            drNew1(5) = dr用户("ID")
                            If dtParnet.Rows.Count > 0 Then
                                drNew1(3) = 金额(dtParnet.Rows(0)("count"))
                            End If
                            dt.Rows.Add(drNew1)
                            drNew(3) += 金额(dtParnet.Rows(0)("count"))
                        Next
                    End If
                Next
            Next
        Else
            Dim dt支出类型 As DataTable = ct.FillTable("select * from XscBugType where ParentID=179 ")
            For Each dr2 As DataRow In dt支出类型.Rows
                Dim dt支出类型1 As DataTable = ct.FillTable("select * from XscBugType where ParentID= " & CStr(dr2("id")))
                Dim drNew As DataRow = dt.NewRow
                drNew(1) = "+" & dr2("name")
                drNew(2) = ""
                drNew(3) = 0
                drNew(4) = dr2("ID")
                dt.Rows.Add(drNew)

                strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr2("id"))
                Dim dtParnet As DataTable = ct.FillTable(strSql1)
                If dtParnet.Rows.Count > 0 Then
                    drNew(3) = 金额(dtParnet.Rows(0)("count"))
                End If

                If dt支出类型1.Rows.Count > 0 Then
                    drNew(1) = "+" & dr2("name") & "(" & dt支出类型1.Rows.Count.ToString & "个小类" & ")"
                    For Each dr3 As DataRow In dt支出类型1.Rows
                        strSql1 = "select  sum(count) as count from WysOutput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr3("id"))
                        dtParnet = ct.FillTable(strSql1)
                        Dim drNew1 As DataRow = dt.NewRow
                        drNew1(1) = ""
                        drNew1(2) = dr3("name")
                        drNew1(3) = 0
                        drNew1(4) = dr3("ID")
                        drNew(4) = drNew(4) & "," & dr3("ID")
                        If dtParnet.Rows.Count > 0 Then
                            drNew1(3) = 金额(dtParnet.Rows(0)("count"))
                        End If
                        dt.Rows.Add(drNew1)
                        drNew(3) += 金额(dtParnet.Rows(0)("count"))
                    Next
                End If
            Next
        End If

        'dr = dt.NewRow
        'dr(1) = 0
        'dr(2) = ""
        'dr(3) = 0

        'dr(1) = "合计"
        'For i As Integer = 0 To dt.Rows.Count - 1
        '    If CStr(dt.Rows(i)(1)).StartsWith("+") Then
        '        dr(3) += 结果(dt.Rows(i)(3))
        '    End If
        'Next
        'dt.Rows.Add(dr)

        Dim dr合计 As DataRow = dt.NewRow
        dr合计(1) = ""
        dr合计(2) = ""
        dr合计(3) = 0

        dr合计(1) = "总合计"
        For i As Integer = 0 To dt.Rows.Count - 1
            If CStr(dt.Rows(i)(1)).StartsWith("+") Then
                dr合计(3) += 结果(dt.Rows(i)(3))
            End If
        Next

        If chk支出用户.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                dr = dt.NewRow
                dr(0) = dr用户("username")
                dr(2) = ""
                dr(3) = 0
                dr(4) = 0
                dr(5) = dr用户("id")
                dr(1) = "小计"
                For i As Integer = 0 To dt.Rows.Count - 1
                    If CStr(dt.Rows(i)("支出用户ID")).Trim = CStr(dr用户("id")).Trim Then
                        dr(3) += 结果(dt.Rows(i)(3))
                    End If
                Next
                dt.Rows.Add(dr)
            Next
        End If
        '合计行
        dt.Rows.Add(dr合计)

        Me.DataGridView4.DataSource = dt
        If Me.chk支出用户.Checked Then
            Me.DataGridView4.Columns("支出用户").Visible = True
            Me.DataGridView4.Width = 637
        Else
            Me.DataGridView4.Columns("支出用户").Visible = False
            Me.DataGridView4.Width = 537
        End If
        Me.DataGridView4.Columns("支出用户ID").Visible = False
        着色(DataGridView4)
    End Sub

    Private Sub LoadData4()
        Dim 开始时间 As Date = New Date(Me.dt开始分类1.Value.Year, Me.dt开始分类1.Value.Month, dt开始分类1.Value.Day)
        Dim 结束时间 As Date = New Date(Me.dt结束分类1.Value.Year, Me.dt结束分类1.Value.Month, dt结束分类1.Value.Day)
        If 开始时间 > 结束时间 Then
            Exit Sub
        End If

        Dim dt As New DataTable
        Dim dc As DataColumn
        dt.Columns.Add("收入用户")
        dt.Columns.Add("支出大类")
        dt.Columns.Add("支出小类")
        dc = dt.Columns.Add("合计", GetType(Decimal))
        dc.DefaultValue = 0
        dt.Columns.Add("分类ID")
        dc = dt.Columns.Add("收入用户ID")
        dc.DefaultValue = ""
        '抽数据
        Dim Year As Integer = Me.dtFindDate.Value.Year
        Dim endmouth As Integer = 0
        Dim strSql As String = String.Empty
        Dim strSql1 As String = String.Empty
        Dim dr As DataRow
        Dim strBegin As String = dt开始分类1.Value.Year.ToString("0000") + "-" + dt开始分类1.Value.Month.ToString("00") + "-" + dt开始分类1.Value.Day.ToString("00")
        Dim strEnd As String = dt结束分类1.Value.Year.ToString("0000") + "-" + dt结束分类1.Value.Month.ToString("00") + "-" + dt结束分类1.Value.Day.ToString("00")
        Dim dt用户 As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by UserIndex")
        If chk收入用户.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                Dim dt支出类型 As DataTable = ct.FillTable("select * from XscBugType where ParentID=176 ")
                For Each dr2 As DataRow In dt支出类型.Rows
                    Dim dt支出类型1 As DataTable = ct.FillTable("select * from XscBugType where ParentID= " & CStr(dr2("id")))
                    Dim drNew As DataRow = dt.NewRow
                    drNew(0) = dr用户("username")
                    drNew(1) = "+" & dr2("name")
                    drNew(2) = ""
                    drNew(3) = 0
                    drNew(4) = dr2("ID")
                    drNew(5) = dr用户("ID")
                    dt.Rows.Add(drNew)

                    strSql1 = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr2("id") & " AND username='" + CStr(dr用户("id")) + "'")
                    Dim dtParnet As DataTable = ct.FillTable(strSql1)
                    If dtParnet.Rows.Count > 0 Then
                        drNew(3) = 金额(dtParnet.Rows(0)("count"))
                    End If

                    If dt支出类型1.Rows.Count > 0 Then
                        drNew(1) = "+" & dr2("name") & "(" & dt支出类型1.Rows.Count.ToString & "个小类" & ")"
                        For Each dr3 As DataRow In dt支出类型1.Rows
                            strSql1 = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr3("id") & " AND username='" + CStr(dr用户("id")) + "'")
                            dtParnet = ct.FillTable(strSql1)
                            Dim drNew1 As DataRow = dt.NewRow
                            drNew1(1) = ""
                            drNew1(2) = dr3("name")
                            drNew1(3) = 0
                            drNew1(4) = dr3("ID")
                            drNew(4) = drNew(4) & "," & dr3("ID")
                            drNew1(5) = dr用户("ID")
                            If dtParnet.Rows.Count > 0 Then
                                drNew1(3) = 金额(dtParnet.Rows(0)("count"))
                            End If
                            dt.Rows.Add(drNew1)
                            drNew(3) += 金额(dtParnet.Rows(0)("count"))
                        Next
                    End If
                Next
            Next
        Else
            Dim dt支出类型 As DataTable = ct.FillTable("select * from XscBugType where ParentID=176 ")
            For Each dr2 As DataRow In dt支出类型.Rows
                Dim dt支出类型1 As DataTable = ct.FillTable("select * from XscBugType where ParentID= " & CStr(dr2("id")))
                Dim drNew As DataRow = dt.NewRow
                drNew(1) = "+" & dr2("name")
                drNew(2) = ""
                drNew(3) = 0
                drNew(4) = dr2("ID")
                dt.Rows.Add(drNew)

                strSql1 = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr2("id"))
                Dim dtParnet As DataTable = ct.FillTable(strSql1)
                If dtParnet.Rows.Count > 0 Then
                    drNew(3) = 金额(dtParnet.Rows(0)("count"))
                End If

                If dt支出类型1.Rows.Count > 0 Then
                    drNew(1) = "+" & dr2("name") & "(" & dt支出类型1.Rows.Count.ToString & "个小类" & ")"
                    For Each dr3 As DataRow In dt支出类型1.Rows
                        strSql1 = "select  sum(count) as count from WysInput where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and type=" & CStr(dr3("id"))
                        dtParnet = ct.FillTable(strSql1)
                        Dim drNew1 As DataRow = dt.NewRow
                        drNew1(1) = ""
                        drNew1(2) = dr3("name")
                        drNew1(3) = 0
                        drNew1(4) = dr3("ID")
                        drNew(4) = drNew(4) & "," & dr3("ID")
                        If dtParnet.Rows.Count > 0 Then
                            drNew1(3) = 金额(dtParnet.Rows(0)("count"))
                        End If
                        dt.Rows.Add(drNew1)
                        drNew(3) += 金额(dtParnet.Rows(0)("count"))
                    Next
                End If
            Next
        End If
        'dr = dt.NewRow
        'dr(1) = 0
        'dr(2) = ""
        'dr(3) = 0

        'dr(1) = "合计"
        'For i As Integer = 0 To dt.Rows.Count - 1
        '    If CStr(dt.Rows(i)(1)).StartsWith("+") Then
        '        dr(3) += 结果(dt.Rows(i)(3))
        '    End If
        'Next
        'dt.Rows.Add(dr)

        Dim dr合计 As DataRow = dt.NewRow
        dr合计(1) = ""
        dr合计(2) = ""
        dr合计(3) = 0

        dr合计(1) = "总合计"
        For i As Integer = 0 To dt.Rows.Count - 1
            If CStr(dt.Rows(i)(1)).StartsWith("+") Then
                dr合计(3) += 结果(dt.Rows(i)(3))
            End If
        Next

        If chk收入用户.Checked Then
            For Each dr用户 As DataRow In dt用户.Rows
                dr = dt.NewRow
                dr(0) = dr用户("username")
                dr(2) = ""
                dr(3) = 0
                dr(4) = 0
                dr(5) = dr用户("id")
                dr(1) = "小计"
                For i As Integer = 0 To dt.Rows.Count - 1
                    If CStr(dt.Rows(i)("收入用户ID")).Trim = CStr(dr用户("id")).Trim Then
                        dr(3) += 结果(dt.Rows(i)(3))
                    End If
                Next
                dt.Rows.Add(dr)
            Next
        End If
        '合计行
        dt.Rows.Add(dr合计)

        Me.DataGridView5.DataSource = dt
        If Me.chk收入用户.Checked Then
            Me.DataGridView5.Columns("收入用户").Visible = True
            Me.DataGridView5.Width = 637
        Else
            Me.DataGridView5.Columns("收入用户").Visible = False
            Me.DataGridView5.Width = 537
        End If
        Me.DataGridView5.Columns("收入用户ID").Visible = False
        着色(DataGridView5)
    End Sub

    Private Function 金额(ByVal ob As Object) As Decimal
        If ob Is Nothing Then
            Return 0
        End If
        If ob Is DBNull.Value Then
            Return 0
        End If
        Return CDec(ob)
    End Function

    Private Sub ListInOut_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim 开始时间 As Date = New Date(Now.Year, 1, 1)
        Dim 结束时间 As Date = New Date(Now.Year, 12, 1)
        'Me.dtFindDate.Value = 开始时间
        'Me.dtFindDate1.Value = 结束时间

        开始时间 = New Date(Now.Year, Now.Month, 1)
        结束时间 = New Date(Now.Year, Now.Month, Date.DaysInMonth(Now.Year, Now.Month))
        'Me.dt开始日.Value = 开始时间
        'Me.dt结束日.Value = 结束时间

        'Me.dt开始分类.Value = 开始时间
        'Me.dt结束分类.Value = 结束时间
        'Me.dt开始分类1.Value = 开始时间
        'Me.dt结束分类1.Value = 结束时间

        '开始时间 = New Date(Now.Year, 1, 1)
        '结束时间 = New Date(Now.Year, 1, 1)
        'Me.dt开始年.Value = 开始时间
        'Me.dt结束年.Value = 结束时间

        LoadData2()
    End Sub

    Public Function 结果(ByVal ob As Object) As Decimal
        If ob Is Nothing Then
            Return 0
        End If
        If ob Is DBNull.Value Then
            ob = 0
        End If
        Return CDec(ob)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        LoadData()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        LoadData1()
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.SelectedIndex = 0 Then
            LoadData2()
        ElseIf TabControl1.SelectedIndex = 1 Then
            LoadData()
        ElseIf TabControl1.SelectedIndex = 2 Then
            LoadData1()
        ElseIf TabControl1.SelectedIndex = 3 Then
            LoadData3()
        ElseIf TabControl1.SelectedIndex = 4 Then
            LoadData4()
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        LoadData2()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        LoadData3()
    End Sub

    Private Sub DataGridView4_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView4.CellDoubleClick
        If DataGridView4.Rows.Count = 0 Then Exit Sub
        If Me.DataGridView4.SelectedRows.Count = 0 Then Exit Sub

        Dim strBegin As String = dt开始分类.Value.Year.ToString("0000") + "-" + dt开始分类.Value.Month.ToString("00") + "-" + dt开始分类.Value.Day.ToString("00")
        Dim strEnd As String = dt结束分类.Value.Year.ToString("0000") + "-" + dt结束分类.Value.Month.ToString("00") + "-" + dt结束分类.Value.Day.ToString("00")
        Dim strTypeId As String = Me.DataGridView4.SelectedRows(0).Cells("分类ID").Value.ToString
        Dim str用户ID As String = Me.DataGridView4.SelectedRows(0).Cells(5).Value

        If strTypeId = "" Then Exit Sub
        Dim sb As New StringBuilder
        sb.AppendLine(" select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysInputUser.UserName as 支出用户")
        sb.AppendLine("  from WysOutput ")
        sb.AppendLine("left join XscBugType on XscBugType.id =WysOutput.type ")
        sb.AppendLine("left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and WysOutput.type in (" & strTypeId & ") ")
        If chk支出用户.Checked Then
            sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
        End If
        sb.AppendLine(" order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName ")
        Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
            frm.Text = "支出一览"
            frm.strName = Me.strName
            frm.iType = Me.iType
            frm.SQL = sb.ToString
            Dim 显示列 As New StringCollection
            显示列.Add("支出类型")
            显示列.Add("支出去向")
            显示列.Add("支出金额")
            显示列.Add("支出时间")
            显示列.Add("支出用户")
            frm.Width = 500
            frm.Height = 500
            frm.显示列 = 显示列
            frm.ShowDialog()
        End Using
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        LoadData4()
    End Sub

    Private Sub DataGridView5_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView5.CellDoubleClick
        If DataGridView5.Rows.Count = 0 Then Exit Sub
        If Me.DataGridView5.SelectedRows.Count = 0 Then Exit Sub

        Dim strBegin As String = dt开始分类1.Value.Year.ToString("0000") + "-" + dt开始分类1.Value.Month.ToString("00") + "-" + dt开始分类1.Value.Day.ToString("00")
        Dim strEnd As String = dt结束分类1.Value.Year.ToString("0000") + "-" + dt结束分类1.Value.Month.ToString("00") + "-" + dt结束分类1.Value.Day.ToString("00")
        Dim strTypeId As String = Me.DataGridView5.SelectedRows(0).Cells("分类ID1").Value.ToString
        Dim str用户ID As String = Me.DataGridView5.SelectedRows(0).Cells(5).Value


        If strTypeId = "" Then Exit Sub
        Dim sb As New StringBuilder
        sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInputUser.UserName as 收入用户")
        sb.AppendLine("  from WysInput ")
        sb.AppendLine(" left join XscBugType on XscBugType.id =WysInput.type ")
        sb.AppendLine(" left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and WysInput.type in (" & strTypeId & ") ")
        If chk收入用户.Checked Then
            sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
        End If
        sb.AppendLine(" order by WysInput.type,WysInputUser.UserName ")
        Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
            frm.Text = "收入一览"
            frm.strName = Me.strName
            frm.iType = Me.iType
            frm.SQL = sb.ToString
            Dim 显示列 As New StringCollection
            显示列.Add("收入类型")
            显示列.Add("收入来源")
            显示列.Add("收入金额")
            显示列.Add("收入时间")
            显示列.Add("收入用户")
            frm.Width = 500
            frm.Height = 500
            frm.显示列 = 显示列
            frm.ShowDialog()
        End Using
    End Sub


    Private Sub 收入一览ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 收入一览ToolStripMenuItem.Click
        '日
        If Me.TabControl1.SelectedIndex = 2 Then
            If DataGridView2.Rows.Count = 0 Then Exit Sub
            If Me.DataGridView2.SelectedRows.Count = 0 Then Exit Sub
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView2.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月([\d]{2})日")
            Dim str用户ID As String = Me.DataGridView2.SelectedRows(0).Cells(5).Value
            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value

            'If strTypeId = "" Then Exit Sub
            Dim sb As New StringBuilder
            sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInputUser.UserName as 收入用户")
            sb.AppendLine("  from WysInput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysInput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If Me.chk用户日.Checked Then
                sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine(" order by WysInput.type,WysInputUser.UserName ")

            Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
                frm.Text = "收入一览"
                frm.strName = Me.strName
                frm.iType = Me.iType
                frm.SQL = sb.ToString
                Dim 显示列 As New StringCollection
                显示列.Add("收入类型")
                显示列.Add("收入来源")
                显示列.Add("收入金额")
                显示列.Add("收入时间")
                显示列.Add("收入用户")
                frm.Width = 500
                frm.Height = 500
                frm.显示列 = 显示列
                frm.ShowDialog()
            End Using
        End If
        '月
        If Me.TabControl1.SelectedIndex = 1 Then
            If DataGridView1.Rows.Count = 0 Then Exit Sub
            If Me.DataGridView1.SelectedRows.Count = 0 Then Exit Sub
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView1.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月")
            Dim str用户ID As String = Me.DataGridView1.SelectedRows(0).Cells(5).Value

            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "31"

            'If strTypeId = "" Then Exit Sub
            Dim sb As New StringBuilder
            sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInputUser.UserName as 收入用户")
            sb.AppendLine("  from WysInput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysInput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "'  ")
            If chk用户月.Checked Then
                sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("  order by WysInput.type,WysInputUser.UserName")
            Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
                frm.Text = "收入一览"
                frm.strName = Me.strName
                frm.iType = Me.iType
                frm.SQL = sb.ToString
                Dim 显示列 As New StringCollection
                显示列.Add("收入类型")
                显示列.Add("收入来源")
                显示列.Add("收入金额")
                显示列.Add("收入时间")
                显示列.Add("收入用户")
                frm.Width = 500
                frm.Height = 500
                frm.显示列 = 显示列
                frm.ShowDialog()
            End Using
        End If
        '年
        If Me.TabControl1.SelectedIndex = 0 Then
            If DataGridView3.Rows.Count = 0 Then Exit Sub
            If Me.DataGridView3.SelectedRows.Count = 0 Then Exit Sub
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str用户ID As String = Me.DataGridView3.SelectedRows(0).Cells(5).Value
            Dim str日期 As String = Me.DataGridView3.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年")

            Dim strBegin As String = mc.Groups(1).Value & "-" & "01" & "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value & "-" & "12" & "-" & "31"

            'If strTypeId = "" Then Exit Sub
            Dim sb As New StringBuilder
            sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInputUser.UserName as 收入用户")
            sb.AppendLine("  from WysInput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysInput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If chk用户.Checked Then
                sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine(" order by WysInput.type,WysInputUser.UserName ")
            Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
                frm.Text = "收入一览"
                frm.strName = Me.strName
                frm.iType = Me.iType
                frm.SQL = sb.ToString
                Dim 显示列 As New StringCollection
                显示列.Add("收入类型")
                显示列.Add("收入来源")
                显示列.Add("收入金额")
                显示列.Add("收入时间")
                显示列.Add("收入用户")
                frm.Width = 500
                frm.Height = 500
                frm.显示列 = 显示列
                frm.ShowDialog()
            End Using
        End If
    End Sub

    Private Sub 支出一览ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 支出一览ToolStripMenuItem.Click
        '日
        If Me.TabControl1.SelectedIndex = 2 Then
            If DataGridView2.Rows.Count = 0 Then Exit Sub
            If Me.DataGridView2.SelectedRows.Count = 0 Then Exit Sub
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView2.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月([\d]{2})日")
            Dim str用户ID As String = Me.DataGridView2.SelectedRows(0).Cells(5).Value

            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value

            'If strTypeId = "" Then Exit Sub
            Dim sb As New StringBuilder
            sb.AppendLine(" select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysInputUser.UserName as 支出用户")
            sb.AppendLine("  from WysOutput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysOutput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If Me.chk用户日.Checked Then
                sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("   order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName ")
            Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
                frm.Text = "支出一览"
                frm.strName = Me.strName
                frm.iType = Me.iType
                frm.SQL = sb.ToString
                Dim 显示列 As New StringCollection
                显示列.Add("支出类型")
                显示列.Add("支出去向")
                显示列.Add("支出金额")
                显示列.Add("支出时间")
                显示列.Add("支出用户")
                frm.Width = 500
                frm.Height = 500
                frm.显示列 = 显示列
                frm.ShowDialog()
            End Using
        End If
        '月
        If Me.TabControl1.SelectedIndex = 1 Then
            If DataGridView1.Rows.Count = 0 Then Exit Sub
            If Me.DataGridView1.SelectedRows.Count = 0 Then Exit Sub
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView1.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月")
            Dim str用户ID As String = Me.DataGridView1.SelectedRows(0).Cells(5).Value

            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "31"

            'If strTypeId = "" Then Exit Sub
            Dim sb As New StringBuilder
            sb.AppendLine(" select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysInputUser.UserName as 支出用户")
            sb.AppendLine("  from WysOutput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysOutput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "'  ")
            If chk用户月.Checked Then
                sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("  order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName ")
            Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
                frm.Text = "支出一览"
                frm.strName = Me.strName
                frm.iType = Me.iType
                frm.SQL = sb.ToString
                Dim 显示列 As New StringCollection
                显示列.Add("支出类型")
                显示列.Add("支出去向")
                显示列.Add("支出金额")
                显示列.Add("支出时间")
                显示列.Add("支出用户")
                frm.Width = 500
                frm.Height = 500
                frm.显示列 = 显示列
                frm.ShowDialog()
            End Using
        End If
        '年
        If Me.TabControl1.SelectedIndex = 0 Then
            If DataGridView3.Rows.Count = 0 Then Exit Sub
            If Me.DataGridView3.SelectedRows.Count = 0 Then Exit Sub
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView3.SelectedRows(0).Cells(1).Value
            Dim str用户ID As String = Me.DataGridView3.SelectedRows(0).Cells(5).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年")

            Dim strBegin As String = mc.Groups(1).Value & "-" & "01" & "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value & "-" & "12" & "-" & "31"

            'If strTypeId = "" Then Exit Sub
            Dim sb As New StringBuilder
            sb.AppendLine("  select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysInputUser.UserName as 支出用户")
            sb.AppendLine("  from WysOutput ")
            sb.AppendLine("  left join XscBugType on XscBugType.id =WysOutput.type ")
            sb.AppendLine("  left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If chk用户.Checked Then
                sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("   order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName")
            Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
                frm.Text = "支出一览"
                frm.strName = Me.strName
                frm.iType = Me.iType
                frm.SQL = sb.ToString
                Dim 显示列 As New StringCollection
                显示列.Add("支出类型")
                显示列.Add("支出去向")
                显示列.Add("支出金额")
                显示列.Add("支出时间")
                显示列.Add("支出用户")
                frm.Width = 500
                frm.Height = 500
                frm.显示列 = 显示列
                frm.ShowDialog()
            End Using
        End If
    End Sub

    Public Sub 着色(ByVal dv As DataGridView)
        Dim dt用户 As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by username")
        For Each DR As DataRow In dt用户.Rows
            Dim rn As Random = New Random()
            System.Threading.Thread.Sleep(50)
            Dim cl As System.Drawing.Color = System.Drawing.Color.FromArgb(DR("COLOR"))
            For Each dgr As DataGridViewRow In dv.Rows
                If dgr.Cells(dv.ColumnCount - 1).Value.ToString = CStr(DR("id")) Then
                    dgr.DefaultCellStyle.BackColor = cl
                End If
            Next
        Next
        'For i As Integer = 0 To dv.Rows.Count - 1
        '    If CStr(dv.Rows(i).Cells(1).Value) = "小计" OrElse CStr(dv.Rows(i).Cells(1).Value) = "总合计" Then
        '        dv.Rows(i).DefaultCellStyle.BackColor = Drawing.Color.YellowGreen
        '    End If
        'Next

    End Sub

    Private Sub DataGridView3_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellDoubleClick

    End Sub

    Public Function Load支出() As DataTable
        Dim sb As New StringBuilder
        '日
        If Me.TabControl1.SelectedIndex = 2 Then
            If DataGridView2.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView2.SelectedRows.Count = 0 Then Return New DataTable
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView2.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月([\d]{2})日")
            Dim str用户ID As String = Me.DataGridView2.SelectedRows(0).Cells(5).Value

            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value

            sb.AppendLine(" select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysOutput.Memo as 备注,WysInputUser.UserName as 支出用户")
            sb.AppendLine("  from WysOutput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysOutput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If Me.chk用户日.Checked Then
                sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("   order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName ")
        End If
        '月
        If Me.TabControl1.SelectedIndex = 1 Then
            If DataGridView1.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView1.SelectedRows.Count = 0 Then Return New DataTable
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView1.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月")
            Dim str用户ID As String = Me.DataGridView1.SelectedRows(0).Cells(5).Value

            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "31"
            sb.AppendLine(" select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysOutput.Memo as 备注,WysInputUser.UserName as 支出用户")
            sb.AppendLine("  from WysOutput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysOutput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "'  ")
            If chk用户月.Checked Then
                sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("  order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName ")

        End If
        '年
        If Me.TabControl1.SelectedIndex = 0 Then
            If DataGridView3.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView3.SelectedRows.Count = 0 Then Return New DataTable
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView3.SelectedRows(0).Cells(1).Value
            Dim str用户ID As String = Me.DataGridView3.SelectedRows(0).Cells(5).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年")

            Dim strBegin As String = mc.Groups(1).Value & "-" & "01" & "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value & "-" & "12" & "-" & "31"

            sb.AppendLine("  select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysOutput.Memo as 备注,WysInputUser.UserName as 支出用户")
            sb.AppendLine("  from WysOutput ")
            sb.AppendLine("  left join XscBugType on XscBugType.id =WysOutput.type ")
            sb.AppendLine("  left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If chk用户.Checked Then
                sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("   order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName")

        End If

        If Me.TabControl1.SelectedIndex = 3 Then
            If DataGridView4.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView4.SelectedRows.Count = 0 Then Return New DataTable

            Dim strBegin As String = dt开始分类.Value.Year.ToString("0000") + "-" + dt开始分类.Value.Month.ToString("00") + "-" + dt开始分类.Value.Day.ToString("00")
            Dim strEnd As String = dt结束分类.Value.Year.ToString("0000") + "-" + dt结束分类.Value.Month.ToString("00") + "-" + dt结束分类.Value.Day.ToString("00")
            Dim strTypeId As String = Me.DataGridView4.SelectedRows(0).Cells("分类ID").Value.ToString
            Dim str用户ID As String = Me.DataGridView4.SelectedRows(0).Cells(5).Value

            If strTypeId = "" Then Return New DataTable
            sb.AppendLine(" select XscBugType.name as 支出类型, WysOutput.Title as 支出去向,WysOutput.count as 支出金额,date(WysOutput.DateTime)  as 支出时间,WysOutput.Memo as 备注,WysInputUser.UserName as 支出用户")
            sb.AppendLine("  from WysOutput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysOutput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysOutput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and WysOutput.type in (" & strTypeId & ") ")
            If chk支出用户.Checked Then
                sb.AppendLine("  AND WysOutput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine(" order by WysOutput.type,WysOutput.DateTime desc,WysInputUser.UserName ")
        End If

        Dim dt As DataTable = ct.FillTable(sb.ToString())
        Return dt
    End Function
    Public Function Load收入() As DataTable
        Dim sb As New StringBuilder
        '日
        If Me.TabControl1.SelectedIndex = 2 Then
            If DataGridView2.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView2.SelectedRows.Count = 0 Then Return New DataTable
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView2.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月([\d]{2})日")
            Dim str用户ID As String = Me.DataGridView2.SelectedRows(0).Cells(5).Value
            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" + mc.Groups(3).Value

            sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInput.Memo as 备注,WysInputUser.UserName as 收入用户")
            sb.AppendLine("  from WysInput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysInput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If Me.chk用户日.Checked Then
                sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine(" order by WysInput.type,WysInputUser.UserName ")

        End If
        '月
        If Me.TabControl1.SelectedIndex = 1 Then
            If DataGridView1.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView1.SelectedRows.Count = 0 Then Return New DataTable
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str日期 As String = Me.DataGridView1.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年([\d]{2})月")
            Dim str用户ID As String = Me.DataGridView1.SelectedRows(0).Cells(5).Value

            Dim strBegin As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value + "-" + mc.Groups(2).Value + "-" & "31"

            sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInput.Memo as 备注,WysInputUser.UserName as 收入用户")
            sb.AppendLine("  from WysInput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysInput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "'  ")
            If chk用户月.Checked Then
                sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine("  order by WysInput.type,WysInputUser.UserName")
        End If
        '年
        If Me.TabControl1.SelectedIndex = 0 Then
            If DataGridView3.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView3.SelectedRows.Count = 0 Then Return New DataTable
            Dim Year As Integer = 0
            Dim Month As Integer = 0
            Dim Day As Integer = 0
            Dim str用户ID As String = Me.DataGridView3.SelectedRows(0).Cells(5).Value
            Dim str日期 As String = Me.DataGridView3.SelectedRows(0).Cells(1).Value
            Dim mc As Match = Regex.Match(str日期, "([\d]{4})年")

            Dim strBegin As String = mc.Groups(1).Value & "-" & "01" & "-" & "01"
            Dim strEnd As String = mc.Groups(1).Value & "-" & "12" & "-" & "31"

            sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInput.Memo as 备注,WysInputUser.UserName as 收入用户")
            sb.AppendLine("  from WysInput ")
            sb.AppendLine("left join XscBugType on XscBugType.id =WysInput.type ")
            sb.AppendLine("left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' ")
            If chk用户.Checked Then
                sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine(" order by WysInput.type,WysInputUser.UserName ")
        End If

        If Me.TabControl1.SelectedIndex = 4 Then
            If DataGridView5.Rows.Count = 0 Then Return New DataTable
            If Me.DataGridView5.SelectedRows.Count = 0 Then Return New DataTable

            Dim strBegin As String = dt开始分类1.Value.Year.ToString("0000") + "-" + dt开始分类1.Value.Month.ToString("00") + "-" + dt开始分类1.Value.Day.ToString("00")
            Dim strEnd As String = dt结束分类1.Value.Year.ToString("0000") + "-" + dt结束分类1.Value.Month.ToString("00") + "-" + dt结束分类1.Value.Day.ToString("00")
            Dim strTypeId As String = Me.DataGridView5.SelectedRows(0).Cells("分类ID1").Value.ToString
            Dim str用户ID As String = Me.DataGridView5.SelectedRows(0).Cells(5).Value


            If strTypeId = "" Then Return New DataTable
            sb.AppendLine(" select XscBugType.name as 收入类型, WysInput.Title as 收入来源,WysInput.count as 收入金额,date(WysInput.DateTime)  as 收入时间,WysInput.Memo as 备注,WysInputUser.UserName as 收入用户")
            sb.AppendLine("  from WysInput ")
            sb.AppendLine(" left join XscBugType on XscBugType.id =WysInput.type ")
            sb.AppendLine(" left join WysInputUser on WysInputUser.id =WysInput.username where date([DateTime])>='" + strBegin + "' and date([DateTime])<='" + strEnd + "' and WysInput.type in (" & strTypeId & ") ")
            If chk收入用户.Checked Then
                sb.AppendLine("  AND WysInput.USERNAME='" + str用户ID + "'")
            End If
            sb.AppendLine(" order by WysInput.type,WysInputUser.UserName ")
        End If

        Dim dt As DataTable = ct.FillTable(sb.ToString())

        Return dt
    End Function

    Private Sub DataGridView3_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView3.SelectionChanged, DataGridView2.SelectionChanged, DataGridView1.SelectionChanged, DataGridView5.SelectionChanged, DataGridView4.SelectionChanged
        If 收入支出ToolStripMenuItem.Checked Then
            得到支出收入窗体.Set支出收入数据(Load支出(), Load收入())
        End If
    End Sub

    Private Sub 收入支出ToolStripMenuItem_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 收入支出ToolStripMenuItem.CheckStateChanged
        If 收入支出ToolStripMenuItem.Checked Then
            得到支出收入窗体.Location = New System.Drawing.Point(Me.Location.X + Me.Width + 5, Me.Location.Y)
            得到支出收入窗体.Show(Me)
        End If
    End Sub

    Public Function 得到支出收入窗体() As InOutForm
        If _InOutForm Is Nothing OrElse _InOutForm.IsDisposed Then
            _InOutForm = New InOutForm
        End If
        Return _InOutForm
    End Function

    Private Sub _InOutForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles _InOutForm.FormClosing
        收入支出ToolStripMenuItem.Checked = False
    End Sub

    Public Overrides Sub 保存窗体数据到数据库(ByRef dtData As System.Data.DataTable)
        '年
        dtData.Rows.Add(New String() {"年开始", "", dt开始年.Value.ToString("yyyy-MM-dd")})
        dtData.Rows.Add(New String() {"年结束", "", dt结束年.Value.ToString("yyyy-MM-dd")})
        If chk用户.Checked Then
            dtData.Rows.Add(New String() {"年分", "", "是"})
        Else
            dtData.Rows.Add(New String() {"年分", "", "否"})
        End If
        '月
        dtData.Rows.Add(New String() {"月开始", "", dtFindDate.Value.ToString("yyyy-MM-dd")})
        dtData.Rows.Add(New String() {"月结束", "", dtFindDate1.Value.ToString("yyyy-MM-dd")})
        If chk用户月.Checked Then
            dtData.Rows.Add(New String() {"月分", "", "是"})
        Else
            dtData.Rows.Add(New String() {"月分", "", "否"})
        End If
        '日
        dtData.Rows.Add(New String() {"日开始", "", dt开始日.Value.ToString("yyyy-MM-dd")})
        dtData.Rows.Add(New String() {"日结束", "", dt结束日.Value.ToString("yyyy-MM-dd")})
        If chk用户日.Checked Then
            dtData.Rows.Add(New String() {"日分", "", "是"})
        Else
            dtData.Rows.Add(New String() {"日分", "", "否"})
        End If
        '支出
        dtData.Rows.Add(New String() {"分类开始", "", dt开始分类.Value.ToString("yyyy-MM-dd")})
        dtData.Rows.Add(New String() {"分类结束", "", dt结束分类.Value.ToString("yyyy-MM-dd")})
        If chk支出用户.Checked Then
            dtData.Rows.Add(New String() {"分类分", "", "是"})
        Else
            dtData.Rows.Add(New String() {"分类分", "", "否"})
        End If
        '收入
        dtData.Rows.Add(New String() {"分类1开始", "", dt开始分类1.Value.ToString("yyyy-MM-dd")})
        dtData.Rows.Add(New String() {"分类1结束", "", dt结束分类1.Value.ToString("yyyy-MM-dd")})
        If chk收入用户.Checked Then
            dtData.Rows.Add(New String() {"分类1分", "", "是"})
        Else
            dtData.Rows.Add(New String() {"分类1分", "", "否"})
        End If
        '
        dtData.Rows.Add(New String() {"选择项", "", Me.TabControl1.SelectedIndex.ToString})
        MyBase.保存窗体数据到数据库(dtData)
    End Sub

    Public Overrides Sub 存取数据库数据到窗体(ByVal dtDbData As System.Data.DataTable)

        If dtDbData.Rows.Count > 0 Then
            '年
            dt开始年.Value = 查找数据("年开始", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            dt结束年.Value = 查找数据("年结束", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            chk用户.Checked = IIf(查找数据("年分", "", "否", dtDbData) = "否", False, True)
            '月
            dtFindDate.Value = 查找数据("月开始", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            dtFindDate1.Value = 查找数据("月结束", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            chk用户月.Checked = IIf(查找数据("月分", "", "否", dtDbData) = "否", False, True)
            '日
            dt开始日.Value = 查找数据("日开始", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            dt结束日.Value = 查找数据("日结束", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            chk用户日.Checked = IIf(查找数据("日分", "", "否", dtDbData) = "否", False, True)
            '支出
            dt开始分类.Value = 查找数据("分类开始", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            dt结束分类.Value = 查找数据("分类结束", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            chk支出用户.Checked = IIf(查找数据("分类分", "", "否", dtDbData) = "否", False, True)
            '收入
            dt开始分类1.Value = 查找数据("分类1开始", "", Now.ToString("yyyy-MM-dd"), dtDbData)
            dt结束分类1.Value = 查找数据("分类1结束", "", Now.ToString("yyyy-MM-dd"), dtDbData)

            chk收入用户.Checked = IIf(查找数据("分类1分", "", "否", dtDbData) = "否", False, True)
            Me.TabControl1.SelectedIndex = CInt(查找数据("选择项", "", 0, dtDbData))

        End If
        MyBase.存取数据库数据到窗体(dtDbData)
    End Sub
End Class
